﻿using LightingPlatform.Tools;
using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Linq;
using System.Threading.Tasks;

namespace LightingPlatform.ViewModel
{
    internal enum ResourceType
    {
        ProductTypes = 1,
        UseArea = 2,
        Orgin = 3,
        ImpactType = 4,
        LightingExplain = 5,
        WorkVoltage = 6,
        ControlType = 7,
        LightingType = 8,
        SetupType = 9
    }

    public class ResourceProvider
    {
        private static List<ResItem> _resItems;

        public async Task GetStaticResource()
        {
            if (_resItems == null)
            {
                _resItems = new List<ResItem>();

                WebServiceProxy proxy = new WebServiceProxy();
                ResArray resArray = await proxy.GetStaticResource();
                _resItems.AddRange(resArray.ResList);
            }
        }

        public IEnumerable<ResItem> ProdTypes
        {
            get
            {
                return  from r in _resItems
                        where r.Id == (int)ResourceType.ProductTypes
                        orderby r.ItemID
                        select r;
            }
        }


        public IEnumerable<ResItem> UseArea
        {
            get
            {
                return from r in _resItems
                       where r.Id == (int)ResourceType.UseArea
                       orderby r.ItemID
                       select r;
            }
        }


        public IEnumerable<ResItem> Orgin
        {
            get
            {
                return from r in _resItems
                       where r.Id == (int)ResourceType.Orgin
                       orderby r.ItemID
                       select r;
            }
        }


        public IEnumerable<ResItem> ImpactType
        {
            get
            {
                return from r in _resItems
                       where r.Id == (int)ResourceType.ImpactType
                       orderby r.ItemID
                       select r;
            }
        }

        public IEnumerable<ResItem> LightingExplain
        {
            get
            {
                return from r in _resItems
                       where r.Id == (int)ResourceType.LightingExplain
                       orderby r.ItemID
                       select r;
            }
        }

        public IEnumerable<ResItem> WorkVoltage
        {
            get
            {
                return from r in _resItems
                       where r.Id == (int)ResourceType.WorkVoltage
                       orderby r.ItemID
                       select r;
            }
        }

        public IEnumerable<ResItem> ControlType
        {
            get
            {
                return from r in _resItems
                       where r.Id == (int)ResourceType.ControlType
                       orderby r.ItemID
                       select r;
            }
        }

        public IEnumerable<ResItem> LightingType
        {
            get
            {
                return from r in _resItems
                       where r.Id == (int)ResourceType.LightingType
                       orderby r.ItemID
                       select r;
            }
        }

        public IEnumerable<ResItem> SetupType
        {
            get
            {
                return from r in _resItems
                       where r.Id == (int)ResourceType.SetupType
                       orderby r.ItemID
                       select r;
            }
        }
    }
}
